/*
 * Digital Audio Mobile - A multi track studio for Windows Mobile
 * Copyright (C) 2008 David Olsson
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "Composition.h"
#include "CompositionInfoControl.h"
#include "DamDialog.h"

CompositionInfoControl::CompositionInfoControl(DamDialog *parent, const Composition *composition, Device *inDev, Device *outDev) throw(): Control(parent, 0, parent->height() - 24, parent->width(), 24), m_hPlayStop(0), m_hRec(0), m_hBpm(0), m_hSignature(0), m_hPos(0), m_inDev(inDev), m_outDev(outDev) {
    m_hPlayStop = CreateWindow(TEXT("BUTTON"), TEXT("Play"), WS_CHILD | WS_VISIBLE | BS_CENTER | BS_PUSHBUTTON, 0, 0, Dialog::widthToPixels(24), Dialog::heightToPixels(24), hWnd(), 0, parent->hInstance(), 0);
    m_hRec = CreateWindow(TEXT("BUTTON"), TEXT("Rec"), WS_CHILD | WS_DISABLED | WS_VISIBLE | BS_CENTER | BS_PUSHBUTTON, Dialog::widthToPixels(24), 0, Dialog::widthToPixels(24), Dialog::heightToPixels(24), hWnd(), 0, parent->hInstance(), 0);
    m_hBpm = CreateWindow(TEXT("STATIC"), TEXT("BPM:"), WS_CHILD | WS_VISIBLE | SS_LEFT | SS_NOPREFIX, Dialog::widthToPixels(52), Dialog::heightToPixels(4), Dialog::widthToPixels((width() - 56) / 2), Dialog::heightToPixels(8), hWnd(), 0, parent->hInstance(), 0);
    m_hSignature = CreateWindow(TEXT("STATIC"), TEXT("Sig:"), WS_CHILD | WS_VISIBLE | SS_LEFT | SS_NOPREFIX, Dialog::widthToPixels(52), Dialog::heightToPixels(12), Dialog::widthToPixels((width() - 56) / 2), Dialog::heightToPixels(8), hWnd(), 0, parent->hInstance(), 0);
    m_hPos = CreateWindow(TEXT("STATIC"), TEXT("Pos:"), WS_CHILD | WS_VISIBLE | SS_LEFT | SS_NOPREFIX, Dialog::widthToPixels((width() - 56) / 2 + 56), Dialog::heightToPixels(4), Dialog::widthToPixels((width() - 56) / 2), Dialog::heightToPixels(8), hWnd(), 0, parent->hInstance(), 0);

    m_inDev->addBufferHandler(this);
    m_outDev->addBufferHandler(this);
}

CompositionInfoControl::~CompositionInfoControl() {
    DestroyWindow(m_hPos);
    DestroyWindow(m_hSignature);
    DestroyWindow(m_hBpm);
    DestroyWindow(m_hRec);
    DestroyWindow(m_hPlayStop);
}

void CompositionInfoControl::paint(HDC hDc) const throw() {
}

void CompositionInfoControl::controlNotification(HWND hCtrl, WPARAM notification) throw() {
    if(hCtrl == m_hPlayStop) {
        static_cast<DamDialog *>(parent())->togglePlay();
    }
}

void CompositionInfoControl::click(unsigned int x, unsigned int y) throw() {
}

void CompositionInfoControl::started(Device *device) throw() {
    if(device == m_outDev) {
        SetWindowText(m_hPlayStop, TEXT("Stop"));
    }
}

void CompositionInfoControl::stopped(Device *device) throw() {
    if(device == m_outDev) {
        SetWindowText(m_hPlayStop, TEXT("Play"));
    }
}

void CompositionInfoControl::bufferCompleted(Device *device, const AudioBuffer *buffer) throw() {
}
